#include <iostream>
using namespace std;
double factorial(int);
int main() {
	int i, n, cnt = 0;
	double primenumber[21];	
	static double sum = 0;
	cout << "Please input a number: ";
	cin >> n;
	for (i = 1; i <= n; i++) 
	{
		cout << factorial(i);
		sum += factorial(i);
		cnt++;
		if (cnt % 2)
			cout << "    ";
		else
			cout << endl;
	}
	if (cnt % 2 == 1)
		cout << endl;
	cout << "The sum is: ";
	printf("%le\n", sum);
	return 0;
}
double factorial(int x) 
{ 
	if (x <= 0)
		return 1;	
	else
		return x * factorial(x - 1); 
}